package io.gitee.wminyu.day07.Recursive;

import org.junit.Test;

public class ArraysMax {



    //for循环求数组的最大值
    public  int array(int arrays[],int count){
        int max=arrays[0];
      for (int i = 0; i<count; i++){
          if (arrays[i]>max){
              max=arrays[i];
          }
      } return max;
    }

    //递归求数组的最大值

    public int getMax(int max,int point,int[] aim){
        if(point==aim.length) //临界值
            return max;
//未达到临界值时，取max值，并进行递归
        max = max >= aim[point] ? max : aim[point];
        return getMax(max,point+1,aim);
    }

@Test
    public void test() {
        int ar[] = {1,2,73,5,6};
        System.out.print(array(ar,5));
    }

    @Test
    public void test2(){
        int ar[] = {1,2,73,5,6};

        int max = ar[0];
        int point = 0;
        System.out.println(max = getMax(max,point,ar));
    }
}
